package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo2 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(3, 4));
        list.add(new Point(1, 67));
        list.add(new Point(36, 46));
        list.add(new Point(37, 49));
        list.add(new Point(90, 89));
        list.add(new Point(9, 68));
        System.out.println(list);

        Collections.sort(list,
                (o1, o2) ->
                        o1.getX() * o1.getX() + o1.getY() * o1.getY()
                                - o2.getX() * o2.getX() + o2.getY() * o2.getY()
        );
        System.out.println(list);
    }
}
